package com.yunze.quartz.task.yunze.Automation;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**2022年10月28日15:15:08
 * 定时任务 自动化 邮件抄送整合
 * @author czc
 */
@Slf4j
@Component("emaiApiSynSend")
public class EmaiApiSynSend {
    public EmaiApiSynSend() {
    }

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void Send(String trigger_type) {
        //1.创建路由 绑定 生产队列 发送消息
        //导卡 路由队列
        String polling_queueName = "admin_EmaiApiSynSend_queue";
        String polling_routingKey = "admin.EmaiApiSynSend.queue";
        String polling_exchangeName = "admin_exchange";//路由
        try {
            Map<String, Object> start_type = new HashMap<>();
            start_type.put("trigger_type", trigger_type);//启动类型
            rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_type), message -> {
                // 设置消息过期时间 30 分钟 过期
                message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                return message;
            });
        } catch (Exception e) {
            System.out.println("自动化-邮件抄送 失败 " + e.getMessage().toString());
        }

    }
}